<template>
 

  <a-modal :title="title" :width="400"  :visible="visible" @ok="handleSubmit" @cancel="handleCancel" cancelText="取消" okText="确定"
     >
    <a-form :form="addOrEditForm" >
      <a-form-item v-if="data.menuKey == 1">
       上级目录：{{data.title}}
     </a-form-item>
     <a-form-item>
      <a-input v-model="data.mlmc" placeholder="请输入目录名称"  ></a-input>
    </a-form-item>
    </a-form>
    
  </a-modal>
</template>


<script> 
import { httpAction, getAction } from '@/api/manage'
import { mapGetters } from 'vuex'

export default {
  name: 'DaMlGl',
  props: {
    onConfirm:{
      type : Function,
      default: () => {},
    },
    formData :{
      type:Object,
      default: () => {},
    } 
        
      
  },
  data () {
    return {
      labelCol:'',
      ajid :'',
      banjieremark:'',
      visible: false,
      wrapperCol:'',
      title: '粘贴文书内容', 
      data:{
        treeKey:'', 
        menuKey:'',
        level:'',
        title:'',
        choose:'',
        mlmc:'',
        ryid:'',
        pid:'',
        mlid:'',
      },
      addOrEditForm: this.$form.createForm(this),
      // form: this.$form.createForm(this), // 只有这样注册后，才能通过表单拉取数据
      url: { 
        add:"/dary/daRyxx/rymladd",
        edit:"/dary/daRyxx/rymledit",
        del:"/dary/daRyxx/rymldel"
      },
    }
  },
  created () {
    console.log("created");
  },

  methods: {
    ...mapGetters(["userInfo"]),
    show(treeKey, menuKey,level,title,choose,ryid,pid,mlid) {
      this.data.treeKey = treeKey; 
      this.data.menuKey = menuKey;
      this.data.level = treeKey;
      this.data.title = title;
      this.data.choose = choose;
      this.data.ryid = ryid;
      this.data.pid = pid;
      this.data.mlid = mlid;
      console.log(this.data);
      if (choose == title){
        this.title = choose;
      }else {
        this.title = choose + title;
      }
      if (menuKey == "1"){
        this.data.mlmc = "";
        this.title = choose + " - 新建目录";
      }
      if (menuKey == "2"){
        this.data.mlmc = title; 
        this.title = choose + " - 修改目录";
      }
      
      this.visible = true;
      this.addOrEditForm.resetFields();
      this.visible = true;
    },
    close () {
      this.$emit('close');
      this.visible = false;
    },
    confirm() {
      console.log("confirm");
      this.onConfirm('子窗体返回的值');
    },
    handleSubmit() {
      let url = "";
      if(this.data.menuKey == "1"){
         url = this.url.add;
      }else{
         url = this.url.edit;
      }
      console.log("上传数据",this.data);
       httpAction(url,this.data,'post').then((res)=>{ 
          if(res.code == "0"){
            this.$emit('ok',this.banjieremark);
            this.close();
            console.log(res);
          }
          }).finally(() => { 
        })   
      // this.addOrEditForm.validateFields((err, values) => {
      //   if (!err) {
          
      //     this.banjieremark = values.bjremark;
          
      //     // this.savebjremark(values.bjremark) 
      //     this.$emit('ok',this.banjieremark);
      //     this.close();
      //     return 
      //   }
      //   console.log("提交失败")
      // })
    },

    handleCancel() {
      this.close()
    },
    handleOk(){

    },
    savebjremark(sm){
      httpAction(this.url.banjie+"?id="+id+"&sm="+sm,'','post').then((res)=>{ 
                    
          if (res.code == "0") {
            this.$message.success(res.msg);
            this.$emit('ok');
            this.close()
          } else {
            this.$message.warning(res.mesmsgsage);
          }
        });
      
    },
    handleConfirmBlur  (e) {
      const value = e.target.value
      this.confirmDirty = this.confirmDirty || !!value
    }
  }
}
</script>

<style scoped>

</style>